package ch.janotta.slawo.da;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.janotta.slawo.da.algirithm.lifecycle.AbilityBasedEntityLifecycleHandlingAlgorithm;
import ch.janotta.slawo.da.algirithm.lifecycle.EntityLifecycleHandlingAlgorithm;
import ch.janotta.slawo.da.algirithm.lifecycle.FullRandomEntityLifecycleHandlingAlgorithm;
import ch.janotta.slawo.da.algirithm.lifecycle.MagelikeEntityLifecycleHandlingAlgorithm;
import ch.janotta.slawo.da.algirithm.lifecycle.RoguelikeEntityLifecycleHandlingAlgorithm;
import ch.janotta.slawo.da.algirithm.lifecycle.WarriorlikeEntityLifecycleHandlingAlgorithm;

public final class EntityFactory {
  private static final Logger LOGGER = LoggerFactory.getLogger(EntityFactory.class);

  private EntityFactory() {}

  public enum GenerationAlgorithm {
    FULL_RANDOM,
    RANDOM_ABILITIES_BASED,
    MAGELIKE,
    ROGUELIKE,
    WARRIORLIKE
  }

  private static HashMap<GenerationAlgorithm, EntityLifecycleHandlingAlgorithm> creationAlgorithmLookupTable = new HashMap<>();
  static {
    creationAlgorithmLookupTable.put(GenerationAlgorithm.FULL_RANDOM, new FullRandomEntityLifecycleHandlingAlgorithm());
    creationAlgorithmLookupTable.put(GenerationAlgorithm.RANDOM_ABILITIES_BASED, new AbilityBasedEntityLifecycleHandlingAlgorithm());
    creationAlgorithmLookupTable.put(GenerationAlgorithm.MAGELIKE, new MagelikeEntityLifecycleHandlingAlgorithm());
    creationAlgorithmLookupTable.put(GenerationAlgorithm.ROGUELIKE, new RoguelikeEntityLifecycleHandlingAlgorithm());
    creationAlgorithmLookupTable.put(GenerationAlgorithm.WARRIORLIKE, new WarriorlikeEntityLifecycleHandlingAlgorithm());
  }

  private static HashMap<CharacterClass, EntityLifecycleHandlingAlgorithm> levelUpAlgorithmLookupTable = new HashMap<>();
  static {
    levelUpAlgorithmLookupTable.put(CharacterClass.MAGE, new MagelikeEntityLifecycleHandlingAlgorithm());
    levelUpAlgorithmLookupTable.put(CharacterClass.ROGUE, new RoguelikeEntityLifecycleHandlingAlgorithm());
    levelUpAlgorithmLookupTable.put(CharacterClass.WARRIOR, new WarriorlikeEntityLifecycleHandlingAlgorithm());
  }

  public static Entity getInstance(GenerationAlgorithm algorithmKey) {
    EntityLifecycleHandlingAlgorithm algorithm = creationAlgorithmLookupTable.get(algorithmKey);
    LOGGER.debug("Using algorithm " + algorithm.getClass().getSimpleName());
    return algorithm.createNewInstance();
  }

  public static EntityLifecycleHandlingAlgorithm getLevelUpAlgorithm(CharacterClass characterClass) {
    return levelUpAlgorithmLookupTable.get(characterClass);
  }
}
